package util;

import com.alibaba.druid.pool.DruidDataSource;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;


public class JDBCUtil {
    private static DruidDataSource dataSource =null;


    static {

        try {
        Properties properties = new Properties();
        properties.load(JDBCUtil.class.getClassLoader().getResourceAsStream("jdbc.properties"));

        dataSource = new DruidDataSource();
        dataSource.setDriverClassName(properties.getProperty("jdbc.driver"));
        dataSource.setUrl(properties.getProperty("jdbc.url"));
        dataSource.setUsername(properties.getProperty("jdbc.username"));
        dataSource.setPassword(properties.getProperty("jdbc.password"));



        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection(){

        try {
            return dataSource.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
